package com.zhifei.web.controller.project;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhifei.common.utils.Constant;
import com.zhifei.common.utils.DownloadTemplateUtil;
import com.zhifei.common.utils.Result;
import com.zhifei.system.domain.vo.DevProjectManhoursVo;
import com.zhifei.system.domain.vo.DevProjectVo;
import com.zhifei.system.service.DevProjectManhoursService;
import com.zhifei.system.service.DevProjectService;
import com.zhifei.system.util.PageUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

@RestController
@RequestMapping("/devProject")
@Api(tags="开发项目管理")
public class DevProjectController {

    @Autowired
    private DevProjectService devProjectService;
    @Autowired
    private DevProjectManhoursService devProjectManhoursService;

    @PostMapping("/import")
    @ApiOperation("导入")
    public Result importMonth(@RequestParam("file")MultipartFile file,@RequestParam("month")String month) {
        return devProjectManhoursService.importMonth(file,month);
    }

    @GetMapping("/downloadTemplate")
    @ApiOperation("工时导入模版下载")
    public void downloadTemplate(HttpServletResponse response){
        try {
            DownloadTemplateUtil.download(response, "工时导入模版");
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    @GetMapping("pageManhours")
    @ApiOperation("分页工时登记列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = Constant.PAGE, value = "当前页码，从1开始", paramType = "query", required = true, dataType="int", defaultValue = "1") ,
            @ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query",required = true, dataType="int", defaultValue = "10"),
            @ApiImplicitParam(name = "projectCode", value = "项目编码", paramType = "query", required = false, dataType = "String"),
            @ApiImplicitParam(name = "jobNum", value = "工号", paramType = "query", required = false, dataType = "String"),
            @ApiImplicitParam(name = "monthStartDate", value = "月份开始时间", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "monthEndDate", value = "月份结束时间", required = false, paramType = "query", dataType = "String")
    })
    public Result<Page<DevProjectManhoursVo>> pageManhours(@ApiIgnore @RequestParam Map<String, Object> params){
        PageUtils page = devProjectManhoursService.pageManhours(params);
        return Result.success(page);
    }

    @GetMapping("page")
    @ApiOperation("分页项目列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = Constant.PAGE, value = "当前页码，从1开始", paramType = "query", required = true, dataType="int", defaultValue = "1") ,
            @ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query",required = true, dataType="int", defaultValue = "10"),
            @ApiImplicitParam(name = "customerName", value = "客户名称", paramType = "query", required = false, dataType = "String"),
            @ApiImplicitParam(name = "projectName", value = "项目名称", paramType = "query", required = false, dataType = "String"),
            @ApiImplicitParam(name = "orderNo", value = "订单编号", paramType = "query", required = false, dataType = "String"),
            @ApiImplicitParam(name = "orderStartDate", value = "下单开始时间", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "orderEndDate", value = "下单结束时间", required = false, paramType = "query", dataType = "String")
    })
    public Result<Page<DevProjectVo>> page(@ApiIgnore @RequestParam Map<String, Object> params){
        PageUtils page = devProjectService.queryPage(params);
        return Result.success(page);
    }


}


